package com.abbas.CayTcore.model

import android.util.Log
import com.abbas.CayTcore.base.BaseModel
import com.abbas.CayTcore.entity.TCoreBase
import com.abbas.CayTcore.subscribeDbResult
import io.reactivex.Observable
import io.reactivex.ObservableEmitter
import io.reactivex.ObservableOnSubscribe
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class AddCoreTypeModel : BaseModel() {

    fun addCore(core: TCoreBase, success: (row: Long) -> Unit, failure: (e: Throwable) -> Unit) {


//        Observable.just(core)
//            .observeOn(Schedulers.io())
//            .subscribeOn(AndroidSchedulers.mainThread())
//            .subscribe({
//                db
//                    .coreDao().insert(core)
//            }, {
//              var a =1
//            }, {
//                success.invoke(1)
//            }).dispose()
        Observable.create<List<Long>> {
            it.onNext(
                db.coreDao()
                    .insert(core)
            )
        }.observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe {

            }
//            .subscribeDbResult({
//                success.invoke(it)
//            }, {
//                failure.invoke(it)
//            })
    }
}